package com.bawei.fuxi.base.mvp;

import android.os.Bundle;

import androidx.annotation.IdRes;
import androidx.fragment.app.Fragment;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.bawei.fuxi.R;


public abstract class BaseFragment<V,P extends BasePresenter<V>>  extends Fragment implements BaseView {
    protected P mPresenter;

    private  View view;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
         view = inflater.inflate(bindLayout(), container, false);
        initView(savedInstanceState);
        mPresenter = createPresenter();
        initData();
        if(mPresenter != null){
            mPresenter.attach((V) this);
        }
        return view;
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        if(mPresenter != null){
            mPresenter.distach();
        }
    }
    public <T extends View> T findViewById(@IdRes int id) {
        return view.findViewById(id);
    }

    public abstract int bindLayout();//返回布局id
    public abstract void initView(Bundle savedInstanceState);//初始化
    public abstract P createPresenter();//创建presenter
    public abstract void initData();//初始化

    @Override
    public void onOk() {

    }

    @Override
    public void onError() {

    }

    @Override
    public void showLoading() {

    }

    @Override
    public void hideLoading() {

    }
}